package com.extr.util;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EhcacheTest {
	private static final String regEx_html = "<[^>]+>";
	private static Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);

	@Cacheable(value = "wordCache")
	public String sayWord(String word) {
		System.out.println("nocache");
		return word;
	}

	@CacheEvict(value = "wordCache", key = "#word")
	public String clearWord(String word) {
		return "Ok";
	}

	public static void main(String args[]){
        Pattern pattern = Pattern.compile("Private (Sub|Function)([\\w\\W]*)End (Sub|Function)");
	    String celVal = "输入n个整数,存放在数组中，输出最大数所在位置(n<=10000)。Private Function Command1_Click()\n" +
				"Dim d(10000) As Integer\n" +
				"d(0) = InputBox(\"请输入元素个数：\")\n" +
				"For i = 1 To d(0)\n" +
				"d(i) = InputBox(\"第\" & i & \"个数据:\")\n" +
				"Next i\n" +
				"maxn = 1\n" +
				"For i = 2 To d(0)\n" +
				"If （1） Then maxn = （2）\n" +
				"Next i\n" +
				"\n" +
				"Print maxn\n" +
				"End Function";

		Matcher matcher = pattern.matcher(celVal);
		System.out.println(matcher.find());
		System.out.println(matcher.start());//返回3
		System.out.println(matcher.end());//返回7
		System.out.println(matcher.group());
		System.out.println("ssss");
//		String sql="1' or '1'='1";
//		System.out.println("防SQL注入:"+ StringEscapeUtils.escapeSql(sql)); //防SQL注入
//
//		System.out.println("转义HTML,注意汉字:"+StringEscapeUtils.escapeHtml("<font>chen磊  xing</font>"));    //转义HTML,注意汉字
//		System.out.println("反转义HTML:"+StringEscapeUtils.unescapeHtml("<font>chen磊  xing</font>"));  //反转义HTML
//
//		System.out.println("转成Unicode编码："+StringEscapeUtils.escapeJava("陈磊兴"));     //转义成Unicode编码
//
//		System.out.println("转义XML："+StringEscapeUtils.escapeXml("<name>陈磊兴</name>"));   //转义xml
//		System.out.println("反转义XML："+StringEscapeUtils.unescapeXml("<name>陈磊兴</name>"));    //转义xml

	}

}
